package utils.common;

import java.text.Collator;
import java.util.*;

/**
 * @Author: hujian
 * @Date: 2019/10/9 13:38
 * @Description: 通过常量构造一个ArrayList返回, 中文排序
 */
public class SampleChineseSort {

    private final static Comparator CHINA_COMPARE = Collator.getInstance(Locale.CHINA);
    private static void sortList(List<String> list){
        list.sort(CHINA_COMPARE);
        for (String str : list){
            System.out.println(str);
        }
    }

    private static void sortArray(String[] attr){
        Arrays.sort(attr, CHINA_COMPARE);
        for (String str : attr){
            System.out.println(str);
        }
    }

    public static void main(String[] args) {
        String[] attr = {"张三", "李四", "王五"};
        List<String> list = Arrays.asList(attr);
        sortList(list);
        sortArray(attr);
    }
}
